package com.newtouch.bxzs.database.synchronize.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.newtouch.bxzs.common.base.model.CooperationCompanyOrganization;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 对端组织架构Mapper
 *
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2020/12/30 10:47</td>
 * <td>Amour</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author yuanjie
 * @version 1.0.0
 * @since 1.0.0
 */
@Mapper
public interface OrganizationOppositeMapper extends BaseMapper<CooperationCompanyOrganization> {

    /**
     * 批量插入对端机构数据
     * @param organizationOpposite 机构数据
     * @return int
     */
    @Insert({"<script>insert into ASSISTANT_COOPERATION_COMPANY_ORGANIZATION(COOPERATION_COMPANY_ORGANIZATION_ID,COOPERATION_COMPANY_ORGANIZATION_CODE," +
            "COOPERATION_COMPANY_ORGANIZATION_NAME,COOPERATION_COMPANY_ORGANIZATION_TELEPHONE,COOPERATION_COMPANY_ORGANIZATION_TYPE," +
            "COOPERATION_COMPANY_ORGANIZATION_DESCRIPTION,COOPERATION_COMPANY_PARENT_ORGANIZATION_CODE,IS_DELETE,IS_ENABLE," +
            "DATA_SOURCE,CREATE_USER_ID,CREATE_TIME,UPDATE_USER_ID,UPDATE_TIME,MEMO,COOPERATION_COMPANY_ORGANIZATION_NAME_FULL_SPELLING) values" +
            "<foreach collection='list' item='item' separator=',' >"+
            "(REPLACE(uuid(),'-',''),#{item.cooperationCompanyOrganizationCode}," +
            "#{item.cooperationCompanyOrganizationName},#{item.cooperationCompanyOrganizationTelephone}," +
            "#{item.cooperationCompanyOrganizationType},#{item.cooperationCompanyOrganizationDescription}," +
            "#{item.cooperationCompanyParentOrganizationCode},#{item.deleteFlag}," +
            "#{item.enableFlag},#{item.dataSource},#{item.createUserId}," +
            "#{item.createTime},#{item.updateUserId},#{item.updateTime},#{item.memo}," +
            "#{item.cooperationCompanyOrganizationNameFullSpelling})" +
            "</foreach>" +
            "ON DUPLICATE KEY UPDATE" +
            " UPDATE_USER_ID = values(CREATE_USER_ID)</script>"})
    int addOrganizationOpposite(@Param("list") List<CooperationCompanyOrganization> organizationOpposite);
}
